package yz;

/**
 * [55. 跳跃游戏](https://leetcode-cn.com/problems/jump-game/)
 *
 * @author Yz
 * @since 2022-09-23 14:31
 */
public class LeetCode55_JumpGame {
    public boolean canJump(int[] nums) {
        if (nums.length == 1 && nums[0] == 0) {
            return true;
        }
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0 && i != nums.length - 1) {
                int aTrue = isTrue(i, nums);
                if (aTrue == 0) {
                    return false;
                }
            }
        }
        return true;
    }
    
    private int isTrue(int i, int[] nums) {
        for (int j = 0; j < i; j++) {
            if (nums[j] + j > i + nums[i]) {
                return 1;
            }
        }
        return 0;
    }
}
